/** 
 * AbstractMultipleFilter.java
 * @author Lex
 * 2007-9-22 ����11:59:57
 */
package org.lex.filter;

import java.util.Iterator;
import java.util.Vector;

import org.lex.utils.Arrays;
import org.lex.utils.collections.Collections;


public abstract class AbstractMultipleFilter<T> implements MultipleFilter<T> {
	protected Vector<Filter<T>> filters = null;

	public AbstractMultipleFilter() {
		super();
		this.filters = new Vector<Filter<T>>();
	}

	public AbstractMultipleFilter(Filter<T>... filters) {
		this();
		// =================================
		if (null != filters)
			for (Filter<T> filter : filters)
				if (null != filter)
					this.add(filter);
	}

	public AbstractMultipleFilter(Iterator<Filter<T>> filters) {
		this(Arrays.toArray(filters));
	}

	public boolean add(Filter<T> filter) {
		return Collections.addUniqueElement(this.filters, filter);
	}

	public boolean remove(Filter<T> filter) {
		return this.filters.remove(filter);
	}

	public boolean contains(Filter<T> filter) {
		return this.filters.contains(filter);
	}

	public void clear() {
		this.filters.clear();
	}

	public Iterator<Filter<T>> iterator() {
		return this.filters.iterator();
	}

	public String toString() {
		StringBuilder buffer = new StringBuilder();
		buffer.append('[').append(getClass().getName()).append(']');
		buffer.append(' ');
		buffer.append(filters.size()).append(" Filters:\n");
		for (Filter filter : filters) {
			buffer.append("[");
			buffer.append(filter.getClass().getName());
			buffer.append("]: ");
			buffer.append(filter.toString());
			buffer.append("\n");
		}
		return buffer.toString();
	}
}
